import  React, { lazy } from "react";
import { useRoutes , Navigate } from "react-router-dom";
import Layout from "../components/layout/index"
import Login from "../views/Login/Login.jsx" 
import Home from "../views/Home/Home.jsx"
// import Room from "../views/Room/Room"
// import Build from "../views/Build/Build"
 import Go from "../views/Go/Go"



const  Room  = lazy(() => import('../views/Room/Room'));
const  Build  = lazy(() => import('../views/Build/Build'));
const RoomList = lazy(()=> import('../views/RoomList/RoomList'))
// 登录页
const frameOut = [
    { path: "/login" , element: <Login />},
    { path: "/go" , element: <Go />}
]

// 功能页
const frameIn = [
    { path:'index',element: <Home />},
    { path:'setroom',element: <Room />},
    { path:'setbuild',element: <Build />},
    { path:'roomlist',element: <RoomList /> },
    { path: "*", element: <Navigate to="/index" /> },
]

const Router = ()=>{

  let element = useRoutes([
    ...frameOut,
    // 把其他功能页面添加到Layout组件里面
    // 如果输入的网址有误就会转到首页
    { path: "/", element: <Navigate to="/index" /> },
    { path: '/*' , element:<Layout />, children: frameIn}

  ]);

  return element
}

export default Router